package com.ruoyi.web.controller.activity;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activity.domain.ActResult;
import com.ruoyi.activity.service.IActResultService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动结果Controller
 * 
 * @author YZD
 * @date 2022-07-13
 */
@Controller
@RequestMapping("/activity/result")
public class ActResultController extends BaseController
{
    private String prefix = "activity/result";

    @Autowired
    private IActResultService actResultService;

    @RequiresPermissions("activity:result:view")
    @GetMapping()
    public String result()
    {
        return prefix + "/result";
    }

    /**
     * 查询活动结果列表
     */
    @RequiresPermissions("activity:result:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActResult actResult)
    {
        startPage();
        List<ActResult> list = actResultService.selectActResultList(actResult);
        return getDataTable(list);
    }

    /**
     * 导出活动结果列表
     */
    @RequiresPermissions("activity:result:export")
    @Log(title = "活动结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActResult actResult)
    {
        List<ActResult> list = actResultService.selectActResultList(actResult);
        ExcelUtil<ActResult> util = new ExcelUtil<ActResult>(ActResult.class);
        return util.exportExcel(list, "活动结果数据");
    }

    /**
     * 新增活动结果
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动结果
     */
    @RequiresPermissions("activity:result:add")
    @Log(title = "活动结果", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActResult actResult)
    {
        actResult.setTime(new Date());
        return toAjax(actResultService.insertActResult(actResult));
    }

    /**
     * 修改活动结果
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ActResult actResult = actResultService.selectActResultById(id);
        mmap.put("actResult", actResult);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动结果
     */
    @RequiresPermissions("activity:result:edit")
    @Log(title = "活动结果", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActResult actResult)
    {
        actResult.setTime(new Date());
        return toAjax(actResultService.updateActResult(actResult));
    }

    /**
     * 删除活动结果
     */
    @RequiresPermissions("activity:result:remove")
    @Log(title = "活动结果", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actResultService.deleteActResultByIds(ids));
    }
}
